from django.db import models


class DateTimeModelMixin(models.Model):
    """自定义创建时间和修改时间的拓展类"""
    c_time = models.DateTimeField('创建时间', auto_now_add=True)
    u_time = models.DateTimeField('修改时间', auto_now=True)

    class Meta:
        abstract = True  # 抽象模型类，迁移不会生成对应的表，只是用于拓展用，给其他模型继承


class IsDeleteModelMixin(models.Model):
    """自定义逻辑删除拓展类"""
    is_delete = models.BooleanField('逻辑删除', default=False, help_text='逻辑删除')

    # 重写delete方法，实现逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    class Meta:
        abstract = True


class ModelsSetMixin(DateTimeModelMixin, IsDeleteModelMixin):
    """自定义整合的模型拓展类"""

    class Meta:
        abstract = True
